﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;

namespace EasyUIDemo.Model
{
    public partial class SalaryContext : DbContext
    {
        public SalaryContext() : base("SalaryDB") { }

        public DbSet<Category> Categories { get; set; }
        public DbSet<Industry> Industries { get; set; }

        public DbSet<Institution> Institutions { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //base.OnModelCreating(modelBuilder);

            EntityTypeConfiguration<Industry> typeConfiguration = modelBuilder.Entity<Industry>();
            typeConfiguration.ToTable("Industries", "Admin");
            //typeConfiguration.Property(x => x.ID).HasColumnName("数据库中的列名");

            modelBuilder.Entity<Category>().ToTable("Categories", "Admin");
            modelBuilder.Entity<Institution>().ToTable("Institutions", "Salary");// Admin.Categories

            //modelBuilder.Entity<CommissionStructure>().HasMany(c => c.CommissionUnits).WithOptional().WillCascadeOnDelete(true);
            //modelBuilder.Entity<CommissionStructure>().HasMany<CommissionUnit>(c => c.CommissionUnits).WithOptional().WillCascadeOnDelete(true);
            // HasMany<TTarget>(Expression<Func<T, ICollection<TTarget>>> expression)

    //        modelBuilder.Entity<Industry>().HasKey(i => i.ID);

    //        modelBuilder.Entity<Institution>().HasRequired(i => i.InstitutionCode)
    //.WithMany(c => c.)
    //.HasForeignKey(p => p.PrimaryCategoryCode);

            //modelBuilder.Entity<Institution>().HasRequired(i => i.Industry).WithMany().HasForeignKey
        }
    }
}
